package com.example.bpmn.lock;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class ProcessLockManager {
    
    private final RedissonClient redissonClient;
    
    public boolean tryLock(String processInstanceId) {
        RLock lock = redissonClient.getLock("process:" + processInstanceId);
        return lock.tryLock();
    }
    
    public void unlock(String processInstanceId) {
        RLock lock = redissonClient.getLock("process:" + processInstanceId);
        if (lock.isHeldByCurrentThread()) {
            lock.unlock();
        }
    }
} 